﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using GalaSoft.MvvmLight;
using Laps.Lib.Core;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight.Messaging;
using Laps.Lib.Messaging;
using System.Windows.Controls;
using System.Reflection;
using System.Web.Services.Description;
using System.CodeDom;

namespace Laps.Lib.ViewModels
{
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
     

        #region Méthodes
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real"
            ////}
            Messenger.Default.Register<FileOpenedMessage>(this, ExecuteOpenAssembly);
        }
        private void CreateProxy()
        {
            ServiceDescription sdescription;
            ServiceDescriptionImporter sdiImporteur;
            CodeNamespace cnNamespace;
            CodeCompileUnit ccuUnit;
            
            try
            {
                sdescription = ServiceDescription.Read("");
                sdiImporteur = new ServiceDescriptionImporter();
                sdiImporteur.ProtocolName = "Soap12";
                sdiImporteur.AddServiceDescription(sdescription, null,null);
                sdiImporteur.Style = ServiceDescriptionImportStyle.Client;
                sdiImporteur.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;
                cnNamespace = new CodeNamespace();
                ccuUnit = new CodeCompileUnit();
                ccuUnit.Namespaces.Add(cnNamespace);
                


            }
            catch (Exception ex)
            {

            }


        }
        private void ExecuteOpenAssembly(FileOpenedMessage message)
        {
            Assembly aProxy;
            try
            {
                if (message.Id == 1)
                {
                    aProxy = Assembly.LoadFile(message.Content);
                    foreach (var temp in aProxy.GetTypes())
                    {
                        Console.WriteLine(temp.Name);
                    }


                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region Propriétés
        #endregion
    }
}
